package com.njmaomao.gj.pyot.common.exception;


import com.njmaomao.gj.pyot.common.ResponseCode;

import java.util.function.Supplier;

/**
 * 业务失败
 *
 */
public class SystemBizFail extends SystemBizException {

    private static final long serialVersionUID = 450681067074732794L;

    public SystemBizFail(ResponseCode responseCode) {
        super(responseCode);
    }

    public SystemBizFail(String code, String desc) {
        super(code, desc);
    }

    public SystemBizFail(String code, String desc, String... format) {
        super(code, String.format(desc, format));
    }

    public static void whenIf(boolean condition, ResponseCode responseCode) {
        if(condition) {
            throw new SystemBizFail(responseCode.getCode(), responseCode.getDesc());
        }
    }

    public static void whenIf(boolean condition, ResponseCode responseCode, Supplier<String[]> format) {
        if(condition) {
            throw new SystemBizFail(responseCode.getCode(), responseCode.getDesc(), format.get());
        }
    }

    public static void whenIf(boolean condition, ResponseCode responseCode, String... format) {
        if(condition) {
            throw new SystemBizFail(responseCode.getCode(), responseCode.getDesc(), format);
        }
    }

    public static void happen(ResponseCode responseCode, String... format) {
        throw new SystemBizFail(responseCode.getCode(), responseCode.getDesc(), format);
    }

}
